<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>角色管理-${sysName}</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" href="${resRoot}/layui/css/layui.css" media="all" />
	<link rel="stylesheet" href="${resRoot}/layui/admin/admin.css" media="all" />
	<link id="layuicss-layer" rel="stylesheet" href="${resRoot}/layui/css/modules/layer/default/layer.css" media="all">
</head>
<body layadmin-themealias="default">
<div class="layui-fluid">   
          <div class="layui-card">
	<div class="layui-form layui-card-header layuiadmin-card-header-auto">
<@shiro.hasPermission name="role:save">
<div class="site-demo-button" style="margin-bottom: 0;">
  <a class="layui-btn linksAdd_btn" style="background-color:#5FB878" href="javascript:void(0);">新增角色</a>
  </div>
</@shiro.hasPermission>
 </div>
  
   <div class="layui-card-body">
<div class="layui-form">

		<table class="layui-table">
    <colgroup>
      <col width="50%">
      <col width="50%">
      <col>
    </colgroup>
    <thead>
      <tr>
        <th>角色名称</th>
        <th>操作</th>
      </tr> 
    </thead>
    <tbody>
    	<#list result.datas as roleDTO>
       	<tr>
	        <td>${roleDTO.roleName}</td>
	        <td>
	        <@shiro.hasPermission name="role:save">
	        <a class="layui-btn layui-btn-normal layui-btn-xs" href="javascript:void(0);" onclick="addData('${roleDTO.id}');" ><i class="iconfont icon-edit"></i>修改</a> 
	        </@shiro.hasPermission>
	        <@shiro.hasPermission name="role:save">
	        <a class="layui-btn layui-btn-normal layui-btn-xs" href="javascript:void(0);" onclick="addData('${roleDTO.id}');"><i class="iconfont"></i>分配</a>
	        </@shiro.hasPermission>
	        <@shiro.hasPermission name="role:del">
	        <a class="layui-btn layui-btn-danger layui-btn-xs" href="javascript:void(0);" onclick="del('${roleDTO.id}');" ><i class="layui-icon"></i>删除</a> 
	        </@shiro.hasPermission>
	        </td>
      	</tr>
      	</#list>
    </tbody>
  </table>
  
	<script type="text/javascript" src="${resRoot}/layui/layui.js"></script>
<div id="page"></div>
<#assign pageUrl= base +'/sys/role/show?'>
	<#include "/page/page1.html">
</div>
</div>
</div>
   </div>
	<script type="text/javascript" src="${resRoot}/js/jquery.min.js"></script>
<script>
layui.use('form', function(){
	  var $ = layui.jquery, form = layui.form;
	  
		$(".linksAdd_btn").click(function(){
			addData();
	  })
		
		 })
		 
		 function addData(id){
				var url = "${base}/sys/role/tosave";
				var titleStr = "添加角色";
				if(id){
					url = "${base}/sys/role/tosave?id=" + id;
					titleStr = "修改角色";
				}
		        var index = layui.layer.open({
		            title : titleStr,
		            type : 2,
		            content : url,
		            success : function(layero, index){
		                var body = layui.layer.getChildFrame('body', index);
		                setTimeout(function(){
		                    layui.layer.tips('点击此处返回', '.layui-layer-setwin .layui-layer-close', {
		                        tips: 3
		                    });
		                },500)
		            }
		        })
		        layui.layer.full(index);
		        //改变窗口大小时，重置弹窗的宽高，防止超出可视区域（如F12调出debug的操作）
		        $(window).on("resize",function(){
		            layui.layer.full(index);
		        })
		    }
function del(id) {
	layer.confirm('确定删除该条角色吗?', function(index){
	$.ajax({
		type : "post",
		url : "${base}/sys/role/del",
		data : {
			id : id
			},
		dataType : "json",
		async : false,
		success : function(data) {
			if(data.message == 0) {
				layer.msg('删除成功！', {
					  icon: 1,
					  time: 2000 //2秒关闭（如果不配置，默认是3秒）
					}, function(){
					  //do something
						window.location.href="${base}/sys/role/show";
					});   
				} else {
				layer.msg("当前角色有用户在使用状态。请先解除绑定角色！");
				}
		}
	}); 
	});   
}

</script>
</body>
</html>